package accounts;

import exceptions.NotEnoughMoneyException;

/**
 * the savings account
 * @author Mike
 */

public class SavingsAccount extends Account {
    private int balance;

    /**
     * creates a new savings account
     * @param _bank the bank
     * @param _accountNr the number of the account
     * @param _owner the customer who owns the account
     */
    public SavingsAccount (int _bank, int _accountNr, int _owner) {
        super(_bank,_accountNr,_owner);
        balance = 0;
    }
    /**
     * withdraw some money from the account
     * @param amount the amount of money to be withdrawn
     */
    public void withdraw (int amount) throws NotEnoughMoneyException {
        if (balance-amount < 0) {
            throw new NotEnoughMoneyException(this);
        }
        Transaction.getBuilder().setType(TType.withdrawl).setAccounts(this,null).setAmount(amount).build();
    }
    /**
     * deposits some money into the account
     * @param amount the amount of money to be deposited
     */
    public void deposit (int amount) {
        Transaction.getBuilder().setType(TType.deposit).setAccounts(null, this).setAmount(amount).build();
    }
    /**
     * returns the balance of the account
     * @return the balance of the account
     */
    public int getBalance () {
        return balance;
    }
}

